Skip to content

Commit

Permalink
Bump SWC to 0.106 (#9967)
Browse files Browse the repository at this point in the history
  • Loading branch information
devongovett committed Sep 29, 2024
1 parent 5b639af commit 684b164
Show file tree
Hide file tree
Showing 22 changed files with 744 additions and 509 deletions.
813 changes: 490 additions & 323 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion crates/macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ napi = ["dep:napi", "dep:napi-derive", "dep:crossbeam-channel"]

[dependencies]
indexmap = "1.9.2"
swc_core = { version = "0.96", features = [
swc_core = { version = "0.106", features = [
"common",
"common_ahash",
"common_sourcemap",
Expand Down
22 changes: 12 additions & 10 deletions crates/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use swc_core::ecma::utils::stack_size::maybe_grow_default;

use indexmap::IndexMap;
use swc_core::{
common::{util::take::Take, SourceMap, Span, DUMMY_SP},
common::{sync::Lrc, util::take::Take, SourceMap, Span, DUMMY_SP},
ecma::{
ast::*,
atoms::{js_word, JsWord},
Expand Down Expand Up @@ -332,7 +332,9 @@ fn is_macro(with: &ObjectLit) -> bool {
if let PropOrSpread::Prop(prop) = &prop {
if let Prop::KeyValue(kv) = &**prop {
let k = match &kv.key {
PropName::Ident(Ident { sym, .. }) | PropName::Str(Str { value: sym, .. }) => sym.clone(),
PropName::Ident(IdentName { sym, .. }) | PropName::Str(Str { value: sym, .. }) => {
sym.clone()
}
_ => continue,
};
if &k == "type"
Expand Down Expand Up @@ -443,9 +445,8 @@ impl<'a> Macros<'a> {
Prop::KeyValue(kv) => {
let v = self.eval(&*kv.value)?;
let k = match &kv.key {
PropName::Ident(Ident { sym, .. }) | PropName::Str(Str { value: sym, .. }) => {
sym.to_string()
}
PropName::Ident(IdentName { sym, .. })
| PropName::Str(Str { value: sym, .. }) => sym.to_string(),
PropName::Num(n) => n.value.to_string(),
PropName::Computed(c) => match self.eval(&*c.expr) {
Err(e) => return Err(e),
Expand Down Expand Up @@ -682,7 +683,7 @@ impl<'a> Macros<'a> {
fn value_to_expr(&self, value: JsValue) -> Result<Expr, MacroError> {
Ok(match value {
JsValue::Null => Expr::Lit(Lit::Null(Null::dummy())),
JsValue::Undefined => Expr::Ident(Ident::new(js_word!("undefined"), DUMMY_SP)),
JsValue::Undefined => Expr::Ident(Ident::new_no_ctxt(js_word!("undefined"), DUMMY_SP)),
JsValue::Bool(b) => Expr::Lit(Lit::Bool(Bool {
value: b,
span: DUMMY_SP,
Expand Down Expand Up @@ -721,7 +722,7 @@ impl<'a> Macros<'a> {
.map(|(k, v)| -> Result<_, MacroError> {
Ok(PropOrSpread::Prop(Box::new(Prop::KeyValue(KeyValueProp {
key: if Ident::verify_symbol(&k).is_ok() {
PropName::Ident(Ident::new(k.into(), DUMMY_SP))
PropName::Ident(IdentName::new(k.into(), DUMMY_SP))
} else {
PropName::Str(Str {
value: k.into(),
Expand All @@ -735,9 +736,10 @@ impl<'a> Macros<'a> {
.collect::<Result<Vec<_>, MacroError>>()?,
}),
JsValue::Function(source) => {
let source_file = self
.source_map
.new_source_file(swc_core::common::FileName::MacroExpansion, source.into());
let source_file = self.source_map.new_source_file(
Lrc::new(swc_core::common::FileName::MacroExpansion),
source.into(),
);
let lexer = Lexer::new(
Default::default(),
Default::default(),
Expand Down
4 changes: 2 additions & 2 deletions packages/core/integration-tests/test/macros.js
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ describe('macros', function () {
});

let res = await overlayFS.readFile(b.getBundles()[0].filePath, 'utf8');
let match = res.match(/output=(\d+)/);
let match = res.match(/output=(.*);/);
assert(match);

b = await bundle(path.join(dir, '/index.js'), {
Expand All @@ -593,7 +593,7 @@ describe('macros', function () {
});

res = await overlayFS.readFile(b.getBundles()[0].filePath, 'utf8');
let match2 = res.match(/output=(\d+)/);
let match2 = res.match(/output=(.*);/);
assert(match2);
assert.notEqual(match[1], match2[1]);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/core/integration-tests/test/transpilation.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ describe('transpilation', function () {
{
message: undefined,
start: {
column: 4,
column: 3,
line: 9,
},
end: {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package-manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"@parcel/types": "2.12.0",
"@parcel/utils": "2.12.0",
"@parcel/workers": "2.12.0",
"@swc/core": "^1.3.36",
"@swc/core": "^1.7.26",
"semver": "^7.5.2"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/optimizers/inline-requires/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"@parcel/plugin": "2.12.0",
"@parcel/source-map": "^2.1.1",
"@parcel/types": "2.12.0",
"@swc/core": "^1.3.36",
"@swc/core": "^1.7.26",
"nullthrows": "^1.1.1"
}
}
2 changes: 1 addition & 1 deletion packages/optimizers/swc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"@parcel/plugin": "2.12.0",
"@parcel/source-map": "^2.1.1",
"@parcel/utils": "2.12.0",
"@swc/core": "^1.3.36",
"@swc/core": "^1.7.26",
"nullthrows": "^1.1.1"
}
}
2 changes: 1 addition & 1 deletion packages/transformers/js/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2021"
crate-type = ["rlib"]

[dependencies]
swc_core = { version = "0.96", features = [
swc_core = { version = "0.106", features = [
"common",
"common_ahash",
"common_sourcemap",
Expand Down
18 changes: 9 additions & 9 deletions packages/transformers/js/core/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub struct Collect {
pub should_wrap: bool,
/// local variable binding -> descriptor
pub imports: HashMap<Id, Import>,
pub this_exprs: HashMap<Id, (Ident, Span)>,
pub this_exprs: HashMap<JsWord, Span>,
/// exported name -> descriptor
pub exports: HashMap<JsWord, Export>,
/// local variable binding -> exported name
Expand Down Expand Up @@ -260,8 +260,8 @@ impl Visit for Collect {
}
self.in_module_this = false;

for (_key, (ident, span)) in std::mem::take(&mut self.this_exprs) {
if self.exports.contains_key(&ident.sym) {
for (key, span) in std::mem::take(&mut self.this_exprs) {
if self.exports.contains_key(&key) {
self.should_wrap = true;
self.add_bailout(span, BailoutReason::ThisInExport);
}
Expand Down Expand Up @@ -601,7 +601,7 @@ impl Visit for Collect {
.or_insert_with(|| node.id.sym.clone());
}

if self.in_assign && node.id.span.has_mark(self.global_mark) {
if self.in_assign && node.id.ctxt.has_mark(self.global_mark) {
self
.non_const_bindings
.entry(id!(node.id))
Expand All @@ -627,7 +627,7 @@ impl Visit for Collect {
.or_insert_with(|| node.key.sym.clone());
}

if self.in_assign && node.key.span.has_mark(self.global_mark) {
if self.in_assign && node.key.ctxt.has_mark(self.global_mark) {
self
.non_const_bindings
.entry(id!(node.key))
Expand Down Expand Up @@ -712,7 +712,7 @@ impl Visit for Collect {
}
} else if !self.in_class {
if let MemberProp::Ident(prop) = &node.prop {
self.this_exprs.insert(id!(prop), (prop.clone(), node.span));
self.this_exprs.insert(prop.sym.clone(), node.span);
}
}
return;
Expand Down Expand Up @@ -750,7 +750,7 @@ impl Visit for Collect {
self.add_bailout(span, BailoutReason::NonTopLevelRequire);
}

if let Some(source) = match_import(node, self.ignore_mark) {
if let Some(source) = match_import(node) {
self.non_static_requires.insert(source.clone());
self.wrapped_requires.insert(source.to_string());
let span = match node {
Expand Down Expand Up @@ -901,7 +901,7 @@ impl Visit for Collect {
Expr::Await(await_exp) => {
// let x = await import('foo');
// let {x} = await import('foo');
if let Some(source) = match_import(&await_exp.arg, self.ignore_mark) {
if let Some(source) = match_import(&await_exp.arg) {
self.add_pat_imports(&node.name, &source, ImportKind::DynamicImport);
return;
}
Expand Down Expand Up @@ -929,7 +929,7 @@ impl Visit for Collect {
}
Expr::Member(member) => {
// import('foo').then(foo => ...);
if let Some(source) = match_import(&member.obj, self.ignore_mark) {
if let Some(source) = match_import(&member.obj) {
if match_property_name(member).map_or(false, |f| &*f.0 == "then") {
if let Some(ExprOrSpread { expr, .. }) = node.args.first() {
let param = match &**expr {
Expand Down
2 changes: 1 addition & 1 deletion packages/transformers/js/core/src/constant_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ mod tests {

fn is_constant_module(code: &str) -> bool {
let source_map = Lrc::new(SourceMap::default());
let source_file = source_map.new_source_file(FileName::Anon, code.into());
let source_file = source_map.new_source_file(Lrc::new(FileName::Anon), code.into());

let comments = SingleThreadedComments::default();
let lexer = Lexer::new(
Expand Down
Loading

0 comments on commit 684b164

Please sign in to comment.